/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PesquisaTexto.java
 *
 * Created on 02/04/2013, 11:46:37
 */
package com.bs.pesquisaView;

import com.bs.extensoesSwing.DocumentFilter;
import javax.swing.JCheckBox;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author Bone
 */
public class PesquisaBoolean extends PesquisaAbstrata {

    private boolean aproximado = true;

    /** Creates new form PesquisaTexto */
    public PesquisaBoolean() {
        initComponents();
    }

    public boolean isAproximado() {
        return aproximado;
    }

    public void setAproximado(boolean aproximado) {
        boolean old = this.aproximado;
        this.aproximado = aproximado;
        firePropertyChange("aproximado", old, aproximado);
    }

    public DocumentFilter getFiltro() {
        return filtro;
    }

    public void setFiltro(DocumentFilter filtro) {
        DocumentFilter old = this.filtro;
        this.filtro = filtro;
        firePropertyChange("filtro", old, filtro);
    }
    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        filtro = new com.bs.extensoesSwing.DocumentFilter();
        valorCheck = new javax.swing.JCheckBox();

        addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                formKeyReleased(evt);
            }
        });

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${campo}"), valorCheck, org.jdesktop.beansbinding.BeanProperty.create("text"));
        binding.setSourceNullValue(null);
        binding.setSourceUnreadableValue(null);
        bindingGroup.addBinding(binding);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(valorCheck, javax.swing.GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(valorCheck, javax.swing.GroupLayout.DEFAULT_SIZE, 23, Short.MAX_VALUE)
        );

        bindingGroup.bind();
    }// </editor-fold>//GEN-END:initComponents

    private void formKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_formKeyReleased
        // TODO add your handling code here:
    }//GEN-LAST:event_formKeyReleased

    @Override
    public Criterion getCriterion() {
        Short valor = null;
        if(valorCheck.isSelected()){
            valor = new Short("1");
        }else{
            valor = new Short("0");
        }
        return Restrictions.eq(getCampo(), valor);
    }

    public boolean getValorCheck() {
        return valorCheck.isSelected();
    }

    public void setValorCheck(boolean valorCheck) {
        this.valorCheck.setSelected(valorCheck);
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private com.bs.extensoesSwing.DocumentFilter filtro;
    private javax.swing.JCheckBox valorCheck;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

    
}
